package yz.cp.back.s.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import yz.cp.back.s.entity.SysRole;
import yz.cp.back.s.entity.SysUserRole;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-04-03
 */
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

    /**
     * 通过用户id获取
     * @param userId
     * @return
     */
    @Select("select r.id id,name,r.data_type from sys_user_role ur left join sys_role r on ur.role_id = r.id where user_id=#{userId}")
    List<SysRole> findByUserId(@Param("userId") String userId);
    /**
     * 通过用户id获取用户角色关联的部门数据
     * @param userId
     * @return
     */
    @Select("select distinct rd.department_id from sys_role_department rd where role_id in (select ur.role_id from sys_user_role ur where ur.user_id = #{userId})")
    List<String> findDepIdsByUserId(@Param("userId") String userId);
}
